package com.lwldjx.auth.domain.service.impl;

import com.lwldjx.auth.common.enums.IsDeletedFlagEnum;
import com.lwldjx.auth.domain.convert.AuthPermissionBOConverter;
import com.lwldjx.auth.domain.convert.AuthRoleBOConverter;
import com.lwldjx.auth.domain.convert.AuthUserBOConverter;
import com.lwldjx.auth.domain.entity.AuthPermissionBO;
import com.lwldjx.auth.domain.entity.AuthRoleBO;
import com.lwldjx.auth.domain.service.AuthPermissionDomainService;
import com.lwldjx.auth.domain.service.AuthRoleDomainService;
import com.lwldjx.auth.infra.basic.entity.AuthPermission;
import com.lwldjx.auth.infra.basic.entity.AuthRole;
import com.lwldjx.auth.infra.basic.entity.AuthUser;
import com.lwldjx.auth.infra.basic.service.AuthPermissionService;
import com.lwldjx.auth.infra.basic.service.AuthRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


@Service
@Slf4j
public class AuthPermissionDomainServiceImpl implements AuthPermissionDomainService {
    @Resource
    private AuthPermissionService authPermissionService;


    @Override
    public Boolean add(AuthPermissionBO authPermissionBO) {
        AuthPermission authPermission = AuthPermissionBOConverter.INSTANCE.convertBOToEntity(authPermissionBO);
        authPermission.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
        Integer count = authPermissionService.insert(authPermission);
        return count > 0;
    }

    @Override
    public Boolean update(AuthPermissionBO authPermissionBO) {
        AuthPermission authPermission = AuthPermissionBOConverter.INSTANCE.convertBOToEntity(authPermissionBO);
        Integer count = authPermissionService.update(authPermission);
        return count > 0;
    }

    @Override
    public Boolean delete(AuthPermissionBO authPermissionBO) {
        AuthPermission authPermission = new AuthPermission();
        authPermission.setId(authPermissionBO.getId());
        authPermission.setIsDeleted(IsDeletedFlagEnum.DELETED.getCode());
        Integer count = authPermissionService.update(authPermission);
        return count > 0;
    }

    @Override
    public Boolean deleteById(AuthPermissionBO authPermissionBo) {
        AuthPermission authPermission = new AuthPermission();
        authPermission.setId(authPermissionBo.getId());
        authPermission.setIsDeleted(IsDeletedFlagEnum.DELETED.getCode());
        long id=authPermission.getId();
        Boolean count = authPermissionService.deleteById(id);
        //有任何的更新，都要与缓存进行同步的修改
        return count ;
    }

    @Override
    public Boolean changeStatus(AuthPermissionBO authPermissionBo) {
        AuthPermission authPermission= AuthPermissionBOConverter.INSTANCE.convertBOToEntity(authPermissionBo);
        Integer count= authPermissionService.update(authPermission);
        return count>0;
    }

    @Override
    public Boolean changeShow(AuthPermissionBO authPermissionBo) {
        AuthPermission authPermission= AuthPermissionBOConverter.INSTANCE.convertBOToEntity(authPermissionBo);
        Integer count= authPermissionService.update(authPermission);
        return count>0;
    }
}
